package com.hpq.user.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hpq.common.domain.vo.request.CursorPageBaseReq;
import com.hpq.common.domain.vo.response.CursorPageBaseResp;
import com.hpq.common.utils.CursorUtils;
import com.hpq.user.domain.model.UserFriend;
import com.hpq.user.domain.vo.response.friend.FriendResp;
import com.hpq.user.mapper.UserFriendMapper;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;

@Service
public class UserFriendDAO extends ServiceImpl<UserFriendMapper, UserFriend> {
    /**
     * 游标翻页获取联系人列表
     * @param uid
     * @param req
     * @return
     */
    public CursorPageBaseResp<UserFriend> getFriendPage(Long uid, CursorPageBaseReq req) {
        return CursorUtils.getCursorPageByMysql(this, req, wrapper -> wrapper.eq(UserFriend::getUid, uid), UserFriend::getId);
    }

    /**
     *  根据uid获取好友列表
     * @param uid
     * @param uidList
     * @return
     */
    public List<UserFriend> getFriendByUids(Long uid, @NotEmpty @Size(max = 50) List<Long> uidList) {
        return lambdaQuery()
                .eq(UserFriend::getUid, uid)
                .in(UserFriend::getFriendUid, uidList)
                .list();
    }

    public UserFriend getFriendByUid(Long uid, @NotNull Long targetUid) {
        return lambdaQuery()
                .eq(UserFriend::getUid, uid)
                .eq(UserFriend::getFriendUid, targetUid)
                .one();
    }

    public List<UserFriend> getUserFriends(Long uid, @org.jetbrains.annotations.NotNull Long targetUid) {

        return lambdaQuery()
                .eq(UserFriend::getUid, uid)
                .eq(UserFriend::getFriendUid, targetUid)
                .or()
                .eq(UserFriend::getUid, targetUid)
                .eq(UserFriend::getFriendUid, uid)
                .list();
    }
}
